package fr.afcepf.atod18.restaurants.web;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import fr.afcepf.atod18.restaurants.entity.Restaurant;
import fr.afcepf.atod18.restaurants.service.IServiceRestaurant;
import fr.afcepf.atod18.utilitaires.entity.InfoSession;

@ManagedBean(name = "listeRestaurantAdminMB")
@SessionScoped
public class ListeRestaurantAdminMB {

    @ManagedProperty(value = "#{serviceRestaurant}")
    private IServiceRestaurant serviceRestaurant;

    private int idSelRestaurant;

    private List<Restaurant> listeRestaurants;
    private InfoSession infoSession;

    /**
     * @return the infoSession
     */
    public InfoSession getInfoSession() {
        return infoSession;
    }

    /**
     * @param infoSession
     *            the infoSession to set
     */
    public void setInfoSession(InfoSession infoSession) {
        this.infoSession = infoSession;
    }

    @PostConstruct
    public void chargementListes() {
         this.listeRestaurants = serviceRestaurant.rechercherTout();

        // recuperation de infoSession
		FacesContext fc = FacesContext.getCurrentInstance();
		if(fc !=null && fc.getExternalContext()!=null){
			infoSession=(InfoSession)fc.getExternalContext().getApplicationMap().get("infoSession");
		}
   }

    public String supprimeRestau() {
        infoSession.setIdSelRestaurant(idSelRestaurant);
        System.out.println("suppression du restaurant : "+ idSelRestaurant);
        return null;
    }
    public String modifieRestau() {
        infoSession.setIdSelRestaurant(idSelRestaurant);
        System.out.println("modification du restaurant : "+ idSelRestaurant);
        return null;
     }
    public String nouveauRestau() {
    	System.out.println("Appel de la page de creation d'un restaurant");
        return "creationRestau.jsf";
   }

    public ListeRestaurantAdminMB() {
        super();
    }
    public List<Restaurant> getListeRestaurants() {
        return listeRestaurants;
    }
    public void setListeRestaurants(List<Restaurant> listeRestaurants) {
        this.listeRestaurants = listeRestaurants;
    }
    /**
     * @return the serviceRestaurant
     */
    public IServiceRestaurant getServiceRestaurant() {
        return serviceRestaurant;
    }
    /**
     * @param paramServiceRestaurant
     *            the serviceRestaurant to set
     */
    public void setServiceRestaurant(IServiceRestaurant paramServiceRestaurant) {
        serviceRestaurant = paramServiceRestaurant;
    }
    /**
     * @return the listeProduitsMB
     */
    /**
     * @return the idSelRestaurant
     */
    public int getIdSelRestaurant() {
        return idSelRestaurant;
    }
    /**
     * @param paramIdSelRestaurant the idSelRestaurant to set
     */
    public void setIdSelRestaurant(int paramIdSelRestaurant) {
        idSelRestaurant = paramIdSelRestaurant;
    }
    
}
